package com.htht.smartschool.action.consume;

import java.util.List;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.consume.TConsume;
import com.htht.smartschool.service.consume.ConsumeService;
import com.htht.smartschool.util.system.GsonUtils;

public class ConsumeAction extends BaseAction{

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		ConsumeService  consumeService = new ConsumeService();
		boolean flag = false;
		TConsume tConsume = (TConsume) GsonUtils.getInstance().fromJson(pd.getData(), TConsume.class);
		if(pd.getCmd().equalsIgnoreCase("addConsume")){
			TConsume consume = consumeService.addConsume(tConsume);
			if(consume != null){
				flag = true;
				obj.setData(consume);
			}else{
				obj.setData("添加消费信息失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteConsume")){
			boolean result = consumeService.deleteConsume(tConsume);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除消费信息失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateConsume")){
			TConsume consume = consumeService.updateConsume(tConsume);
			if(consume != null){
				flag = true;
				obj.setData(consume);
			}else{
				obj.setData("修改消费信息失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getConsume")){
			TConsume tconsume = consumeService.getConsume(tConsume);
			if(tconsume!= null){
				flag = true;
				obj.setData(tconsume);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getConsumeStatistics")){
			List<TConsume> tconsume = consumeService.getConsumeStatistics(tConsume);
			if(tconsume.size() >0){
				flag = true;
				obj.setData(tconsume);
			}else{
				obj.setData("查无数据！");
			}
		}
		return flag;
	}
	
}
